package com.lin.cloud.disk.entity.dto;

import com.lin.cloud.disk.common.enums.EDeleteStatus;
import com.lin.cloud.disk.common.exception.BusinessException;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;

import java.util.Date;
import java.util.List;

/**
 * 逻辑删除实体类
 * @author ljc
 * @date 2021/1/22 17:08
 */
@Data
public class LogicDeleteStatusDTO {

    @ApiModelProperty(value = "业务ID", name = "idList")
    private List<Long> idList;

    @ApiModelProperty(value = "修改人", name = "updateBy")
    private String updateBy;

    @ApiModelProperty(value = "修改时间", name = "updateTime")
    private Date updateTime;

    @ApiModelProperty(value = "删除状态 0 未删除  1 已删除", name = "deleteStatus")
    private Integer deleteStatus;


    /**
     * 获取删除状态实例对象
     * @param idList
     * @param username
     * @return
     */
    public static LogicDeleteStatusDTO getDeleteStatusInstance(List<Long> idList, String username){
        if (CollectionUtils.isEmpty(idList)){
            throw new BusinessException("删除失败,请选择指定ID");
        }
        LogicDeleteStatusDTO dto = new LogicDeleteStatusDTO();
        dto.idList = idList;
        if (StringUtils.isNotBlank(username)){
            dto.updateBy = username;
        }else{
            dto.updateBy = "";
        }
        dto.updateTime = new Date();
        dto.deleteStatus = EDeleteStatus.DELETE.getStatus();
        return dto;
    }


    /**
     * 获取未删除状态实例对象
     * @param idList
     * @param username
     * @return
     */
    public static LogicDeleteStatusDTO getUnDeleteStatusInstance(List<Long> idList, String username){
        if (CollectionUtils.isEmpty(idList)){
            throw new BusinessException("恢复失败,请选择指定ID");
        }
        LogicDeleteStatusDTO dto = new LogicDeleteStatusDTO();
        dto.idList = idList;
        if (StringUtils.isNotBlank(username)){
            dto.updateBy = username;
        }else{
            dto.updateBy = "";
        }
        dto.updateTime = new Date();
        dto.deleteStatus = EDeleteStatus.UN_DELETE.getStatus();
        return dto;
    }

}
